// pages/newqianyuantiaozhuan/newqianyuantiaozhuan.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    flag: true, //设置节流
  },





  zhuce() {
    console.log(111);
    this.setData({
      jiami: app.globalData.jiami,
      openid: app.globalData.openid,
      session_key: app.globalData.session_key,
    })
    if (this.data.flag) {
      this.data.flag = false
      wx.request({
        url: app.globalData.interface+'/newVersion/API_2040_SelectWeixinUser',
        method: 'POST',
        data: {
          OPEN_ID: app.globalData.openid, //用户OPEN_ID
          session_key: app.globalData.session_key,
          OPEN_UUID: app.globalData.jiami,
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: res => {
          if (res.data.result == 'error') {
            wx.showModal({
              title: '温馨提示',
              content: '未注册，请先注册',
              success: function (res) {
                if (res.confirm) {//这里是点击了确定以后
                  wx.navigateTo({
                    url: '../../pages/newquanyizhuce/newquanyizhuce',
                  })
                } else {//这里是点击了取消以后
                  console.log('用户点击取消')
                  wx.navigateTo({
                    url: '../../pages/newquanyizhuce/newquanyizhuce',
                  })
                }
              }
            })           
          } else {
            wx.navigateTo({
              url: '../../pages/newqianyuan/newqianyuan',
            })
          }
        }
      })
      setTimeout(() => {
        this.data.flag = true
      }, 3000)
    }
  },





















  back() {
    wx.navigateBack({
      delta: 1
    })
  },






  //查询是否注册
  lingquan() {
    this.setData({
      openid: app.globalData.openid,
      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      session_key: app.globalData.session_key,
      CUSTOMER_ID: app.globalData.CUSTOMER_ID,
    });
    wx.request({
      url: app.globalData.interface+'/crossVersionOne/API2_1003_QianYuanCouponLogo',
      method: 'POST',
      data: {
        OPEN_ID: this.data.openid, //用户OPEN_ID
        session_key: this.data.session_key,
        OPEN_UUID: this.data.jiami
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log(res);
        console.log(res.data.data);
        this.setData({
          ressj: res.data
        })

        if (res.data.result == 'error') {
          console.log('未注册');
          wx.showModal({
            title: '温馨提示',
            content: '未报名，请先点击报名',
            success: function (res) {
              if (res.confirm) { //这里是点击了确定以后

              } else { //这里是点击了取消以后
                console.log('用户点击取消')
              }
            }
          })

        } else { //往领券跳转时跳转带数据
          wx.navigateTo({
            // url: '../../pages/weihuyancaolingqu/weihuyancaolingqu?data=' + JSON.stringify(this.data.ressj)
            url: '../../pages/newqianyuanlinquan/newqianyuanlinquan?data=' + JSON.stringify(this.data.ressj)

          })
        }

      }
    })
  },























  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})